package com.ymy.thinking.in.spring.dependency.injection;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * 基于 XML 资源的依赖注入
 *
 * @author Ringo
 * @date 2021/9/29 0:29
 */
public class XMLDependencySetterInjectionDemo {

    public static void main(String[] args) {
        final String XML_PATH_LOCATION = "classpath:META-INFO/dependency-injection-setter-configuration.xml";

        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
        // 加载 XML 资源, 解析并生成 BeanDefinition
        beanDefinitionReader.loadBeanDefinitions(XML_PATH_LOCATION);
        // 创建依赖查找并且创建 Bean

        UserHolder userHolder = beanFactory.getBean(UserHolder.class);
        System.out.println(userHolder);

    }

}
